package com.zut.yyzx.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zut.yyzx.dto.MealDTO;
import com.zut.yyzx.pojo.Meal;
import com.zut.yyzx.service.MealService;
import com.zut.yyzx.utils.ResultVo;
import com.zut.yyzx.vo.MealVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/meal")
@CrossOrigin
//"膳食日历管理"
public class MealController {
    @Resource
    private MealService mealService;

    @PostMapping("/addMeal")
    //"添加膳食"
    public ResultVo addMeal(Meal meal) throws Exception{
        mealService.save(meal);
        return ResultVo.ok("添加膳食");
    };

    //"更新膳食"
    @PostMapping("/updateMeal")
    public ResultVo updateMeal(Meal meal) throws Exception{
        mealService.updateById(meal);
        return ResultVo.ok("更新膳食");
    }

    //"删除膳食"
    @GetMapping("/removeMeal")
    public ResultVo removeMeal(Integer id) throws Exception{
        mealService.removeById(id);
        return ResultVo.ok("删除膳食");
    }

    @PostMapping("/listMealPage")
    //"膳食查询（分页）/可以根据星期查询，根据膳食类型（早餐/午餐/晚餐）"
    public ResultVo<Page<MealVo>> listMealPage(MealDTO mealDTO) throws Exception{
        return mealService.listMealVoPage(mealDTO);
    }
}
